import { useUserStore } from '@/store/user'

const hasPermission = function (el, binding) {
  const userStore = useUserStore()
  const { value } = binding
  const permissions = userStore.permissions || []
  let flag = true
  for (const v of value) {
    if (!permissions.includes(v)) {
      flag = false
    }
  }
  if (!flag) {
    if (!el.parentNode) {
      el.style.display = 'none'
    } else {
      el.parentNode.removeChild(el)
    }
  }
}

export default hasPermission
